package com.itmate.wei.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itmate.wei.entity.Family;
import com.itmate.wei.entity.MessageBoard;
import com.itmate.wei.service.MessageBoardService;

/**
 * Servlet implementation class DoaddMes
 */
@WebServlet("/doaddmes")
public class DoaddMes extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoaddMes() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		String content=request.getParameter("content");
		String mes_p=request.getParameter("username");
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");//设置日期格式
		
		String time=df.format(new Date());
		MessageBoardService mb = new MessageBoardService();
		MessageBoardService mb2 = new MessageBoardService();
		MessageBoard m = new MessageBoard();
		m.setContent(content);
		m.setTime(time);
		m.setMes_p(mes_p);
		mb.addMessageBoard(m);
		
		List<MessageBoard> listm=new ArrayList<>();
		
		listm=mb2.SelectAllMB();
		request.setAttribute("list", listm);
		
		
		request.getRequestDispatcher("/WEB-INF/jsp/wei/SeeMessageBoard.jsp").forward(request, response);
		
		
	}

}
